set seed 5181985

*******************
***Main analysis***
*******************

use "Sheriffs and Extremist Violence RD Dataset.dta", clear

**Right-wing violence**
rdrobust violence_right rv
*Standard rdplot using full range*
rdplot violence_right rv, graph_options(title("") ytitle(Violent incidents per county-year) xtitle(Dem vote share (%)) xlabel(-50(10)50) legend(off) graphregion(color(white)))
*rdplot matching estimation in rdrobust (same bandwidth and polynomial order)*
rdplot violence_right rv if inrange(rv, -10.382, 10.382), h(10.382) p(1) graph_options(title("") ytitle(Violent incidents per county-year) xtitle(Dem vote share (%)) legend(off) graphregion(color(white)))
**Left-wing violence**
rdrobust violence_left rv
*Standard rdplot using full range*
rdplot violence_left rv, graph_options(title("") ytitle(Violent incidents per county-year) xtitle(Dem vote share (%)) xlabel(-50 -40 -30 -20 -10 0 10 20 30 40 50) legend(off) graphregion(color(white)))
*rdplot matching estimation in rdrobust (same bandwidth and polynomial order)*
rdplot violence_left rv if inrange(rv, -10.382, 10.382), h(10.382) p(1) graph_options(title("") ytitle(Violent incidents per county-year) xtitle(Dem vote share (%)) legend(off) graphregion(color(white)))
**RD power calculation**
rdpow violence_right rv

****************
***Robustness***
****************

***Different kernels***

rdrobust violence_right rv, kernel(epanechnikov)
rdrobust violence_left rv, kernel(epanechnikov)

rdrobust violence_right rv, kernel(uniform)
rdrobust violence_left rv, kernel(uniform)

***Different bandwidths***

rdrobust violence_right rv, h(5)
rdrobust violence_left rv, h(5)

rdrobust violence_right rv, h(2.5)
rdrobust violence_left rv, h(2.5)

***Combining right and left-wing violence into one outcome***

gen rightleftviolence = violence_right-violence_left

rdrobust rightleftviolence rv

*Poisson w/ 5% bandwidth*

poisson violence_right treat if rv>=-5 & rv<=5

***Above median share of county law enforcement officers only***

**Merging data on local law enforcement**

use "27681-0001-Data.dta", clear

rename COUNTY county
rename STATE state

replace county=upper(county)
replace county = subinstr(county, ".", "",.)
replace county="DUPAGE" if county=="DU PAGE"
replace county="LAPORTE" if county=="LA PORTE"
replace county="LASALLE" if county=="LA SALLE"
replace county="PRINCE GEORGE'S" if county=="PRINCE GEORGES"
replace county="QUEEN ANNE'S" if county=="QUEEN ANNES"
replace county="ST MARY'S" if county=="ST MARYS"

encode county, gen(county_code)
encode state, gen(state_code)

gen sheriff_officers = .
replace sheriff_officers = FTSWORN if AGCYTYPE==1

gen local_officers = .
replace local_officers = FTSWORN if AGCYTYPE==0

*Assign NYPD to outer boroughs*
replace local_officers = 36023 if county_code==208 | county_code==890 | county_code==1354 | county_code==1390

collapse (sum) sheriff_officers local_officers (first) state county, by(state_code county_code)

gen share_sheriff = sheriff/(sheriff+local)

egen concatvar = concat(state county)

merge 1:m concatvar using "Sheriffs and Extremist Violence Dataset.dta"

drop if _merge==1

drop county_code state_code

**Redo analysis w/ above median share officers in sheriff's departments**

*Right-wing violence*
rdrobust violence_right rv if share>=0.35
*Standard rdplot using full range
rdplot violence_right rv if share>=0.35, graph_options(title("") ytitle(Violent incidents per county-year) xtitle(Dem vote share (%)) xlabel(-50(10)50) legend(off) graphregion(color(white)))
*Left-wing violence*
rdrobust violence_left rv if share>=0.35
*Standard rdplot using full range
rdplot violence_left rv if share>=0.35, graph_options(title("") ytitle(Violent incidents per county-year) xtitle(Dem vote share (%)) xlabel(-50 -40 -30 -20 -10 0 10 20 30 40 50) legend(off) graphregion(color(white)))


*************************************
***Mechanisms Het Effects Analysis***
*************************************

***BY SIZE OF SHERIFF DEPARTMENT, FOR INSTITUTIONAL MECHANISM***

**Merging data on local law enforcement**
use "27681-0001-Data.dta", clear

rename COUNTY county
rename STATE state

replace county=upper(county)
replace county = subinstr(county, ".", "",.)
replace county="DUPAGE" if county=="DU PAGE"
replace county="LAPORTE" if county=="LA PORTE"
replace county="LASALLE" if county=="LA SALLE"
replace county="PRINCE GEORGE'S" if county=="PRINCE GEORGES"
replace county="QUEEN ANNE'S" if county=="QUEEN ANNES"
replace county="ST MARY'S" if county=="ST MARYS"

encode county, gen(county_code)
encode state, gen(state_code)

gen sheriff_officers = .
replace sheriff_officers = FTSWORN if AGCYTYPE==1

gen local_officers = .
replace local_officers = FTSWORN if AGCYTYPE==0

*Assign NYPD to outer boroughs*
replace local_officers = 36023 if county_code==208 | county_code==890 | county_code==1354 | county_code==1390

collapse (sum) sheriff_officers local_officers (first) state county, by(state_code county_code)

gen share_sheriff = sheriff/(sheriff+local)

egen concatvar = concat(state county)

merge 1:m concatvar using "Sheriffs and Extremist Violence Dataset.dta"

drop if _merge==1

drop county_code state_code

gen larger=.
replace larger=0 if sheriff_officers<=48
replace larger=1 if sheriff_officers>48

**Analysis**

*Right-wing violence*
rdrobust violence_right rv if larger==0
rdrobust violence_right rv if larger==1
*Standard rdplot using full range
rdplot violence_right rv if larger==0, graph_options(title("") ytitle(Violent incidents per county-year) xtitle(Dem vote share (%)) xlabel(-50(10)50) legend(off) graphregion(color(white)))
rdplot violence_right rv if larger==1, graph_options(title("") ytitle(Violent incidents per county-year) xtitle(Dem vote share (%)) xlabel(-50(10)50) legend(off) graphregion(color(white)))
